package com.aspose.cells;

class zsy {
   static void a(com.aspose.cells.b.a.d.zm var0, Workbook var1, TxtSaveOptions var2) throws Exception {
      com.aspose.cells.b.a.d.zo var3 = var2.a ? new com.aspose.cells.b.a.d.zo(var0) : new com.aspose.cells.b.a.d.zo(var0, var2.getEncoding());
      TxtSaveOptions var4 = var2;
      Cells var5;
      if (zsu.a(var1.getWorksheets())) {
         var5 = var1.getWorksheets().get(0).getCells();
      } else {
         var5 = var1.getWorksheets().get(var1.getWorksheets().getActiveSheetIndex()).getCells();
      }

      try {
         var5.c = new zkv(var5, 16383);
         var5.d = new zkt(var5, 16383);
         a(var3, var5, var4);
      } finally {
         var5.l();
         var5.m();
      }

      var3.c();
      if (var2.getClearData()) {
         var1.initialize();
      } else {
         var1.a();
      }

   }

   private static void a(com.aspose.cells.b.a.d.zo var0, Cells var1, TxtSaveOptions var2) throws Exception {
      zxx var3 = var1.h().getWorkbook().getSettings().e();
      zxu var4 = var3.j();
      boolean var5 = !var1.h().getDisplayZeros();
      String var6 = var2.getSeparatorString();
      String var7;
      if (var2.getQuoteType() == 1) {
         var7 = "\"\"" + var6;
      } else {
         var7 = var6;
      }

      boolean var8 = false;
      int var9 = -1;
      int var10 = var1.getMaxDataColumn();
      if (var10 < 0) {
         var10 = 0;
      }

      zr var11 = var1.f();
      zahl var12 = var11.a(-1, -1, false);
      zfv var14 = new zfv();

      label170:
      while(true) {
         int var16 = var12.a();
         String var25;
         if (var16 < 0) {
            if (zsu.a(var1.r())) {
               String var24 = "\r\nEvaluation Only. Created with " + zakq.b() + ".";
               var25 = "Copyright 2003 - " + DateTime.getNow().getYear() + " Aspose Pty Ltd.";
               String var26 = var24 + var25;
               var0.a(var26);
            }

            return;
         }

         zp var17 = var11.f(var16);

         for(int var18 = 0; var18 < var17.h() - var9 - 1; ++var18) {
            var0.a("\r\n");
         }

         int var23 = 0;
         zahl var13 = var17.a(-1, -1, false);

         while(true) {
            zfv var15;
            do {
               var16 = var13.a();
               if (var16 < 0) {
                  if (var23 <= var10) {
                     var0.a(var6);

                     while(var23 < var10) {
                        var0.a(var7);
                        ++var23;
                     }

                     if (var2.getQuoteType() == 1) {
                        var0.a("\"\"");
                     }
                  }

                  var0.a("\r\n");
                  var9 = var17.h();
                  continue label170;
               }

               var15 = var17.a(var16, var14, 7);
            } while(var15.c == 0);

            if (var23 > 0) {
               var0.a(var6);
            }

            if (var15.a > var23) {
               while(var23 < var15.a) {
                  var0.a(var7);
                  ++var23;
               }
            }

            ++var23;
            var25 = null;
            zfv var19 = var15.d();
            byte var20 = 18;
            switch(var19.c) {
            case 0:
               var25 = "";
               break;
            case 1:
               if (var5 && (Double)var19.d == 0.0D) {
                  var25 = "";
                  break;
               }

               var20 = 14;
               break;
            case 2:
               var20 = 3;
               break;
            case 3:
               var25 = var19.f();
               break;
            case 4:
               var20 = 18;
            case 5:
            default:
               break;
            case 6:
               if (var5 && (Integer)var19.d == 0) {
                  var25 = "";
               } else {
                  var20 = 9;
               }
            }

            if (var25 == null) {
               zxz var21 = var3.a(Cell.a(var1, var17, var15)).a(var4, var20, var19.d);
               if (var21.e()) {
                  var25 = "###############################################################################################################################################################################################################################################################";
               } else {
                  var25 = var21.a(0, true);
               }
            }

            boolean var27 = false;
            switch(var2.getQuoteType()) {
            case 0:
               if (var25.length() > 0) {
                  var27 = var25.indexOf(34) > -1;
                  if (!var27) {
                     var27 = var25.indexOf(10) > -1;
                     if (!var27) {
                        var27 = var25.indexOf(var6) > -1;
                     }
                  }
               }
               break;
            case 1:
               var27 = true;
               break;
            case 2:
               if (var25.length() > 0) {
                  var27 = var25.charAt(0) == '"';
                  if (!var27) {
                     var27 = var25.indexOf(10) > -1;
                     if (!var27) {
                        var27 = var25.indexOf(var6) > -1;
                     }
                  }
               }
            }

            if (var27) {
               String var22 = com.aspose.cells.b.a.zv.a(var25, "\"", "\"\"");
               var22 = '"' + var22 + '"';
               var0.a(var22);
            } else {
               var0.a(var25);
            }
         }
      }
   }
}
